package org.dreamfly.core.action;


import org.dreamfly.core.bean.SzRadio;
import org.dreamfly.core.page.PageResultSet;
import org.dreamfly.core.service.RadioService;

import java.util.List;


public class RadioAction extends BaseAction {
    private PageResultSet<SzRadio> resultSet;
    private SzRadio radio;
    private SzRadio object;
    private RadioService radioService;
    private String title;
    private Long id;
    private List<Long> deleteIds;
    private String server;
    private String note;
    private String isAdmin;
    private String actionName;
    /**
     * 分页参数
     * pageSize 每页的大小
     * page     显示的页码
     */
    private Long pageSize = 5L;
    private Long page = 1L;

    /**
     * 按关键字搜索动作库
     *
     * @return success
     */
    public String searchRadio() {
        if (radio == null) {
            radio = new SzRadio();
            radio.setTitle("%");
        }
        if ("".equals(radio.getTitle())){
            radio.setTitle("%");
        }
        /*try {
            radio.setTitle(new String(radio.getTitle().getBytes("ISO-8859-1"), "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }*/
        if(isAdmin==null){
        	resultSet = radioService.normalSearch(radio, pageSize, page, null);
            resultSet.setActionName("audioNameSearch");
        }else{
        	resultSet = radioService.normalSearch(radio, 15l, page, server);
            resultSet.setActionName("bgAudio");
        }
        resultSet.setType("Audio");
        if (resultSet.getList() == null) {
            return INPUT;
        }
        resultSet.setKeyWords(radio.getTitle());


        return SUCCESS;
    }

    /**
     * 添加音频信息
     *
     * @return
     */
    public String addRadioInfo() {
        SzRadio act = radioService.findDetail(id);
        act.setTitle(title);
        act.setServer(server);
        act.setNote(note);
        radioService.saveOrUpdate(act);
        return SUCCESS;
    }

    /**
     * 修改动作库
     *
     * @return
     */
    public String modifyradio() {
        radioService.saveOrUpdate(radio);
        return SUCCESS;
    }

    public String getAudioInfo(){
        object = radioService.findDetail(id);
        actionName = "modifyAudio";
        return null != object ?SUCCESS :INPUT;
    }
    /**
     * 删除动作库
     *
     * @return
     */
    public String deleteRadio() {
        radioService.delete(id);
        return SUCCESS;
    }

    public String deleteRadioList(){
        for(Long id : deleteIds){
            radioService.delete(id);
        }
        return SUCCESS;
    }
    public PageResultSet<SzRadio> getResultSet() {
        return resultSet;
    }

    public SzRadio getObject() {
        return object;
    }

    public String getAdmin() {
        return isAdmin;
    }

    public void setDeleteIds(List<Long> deleteIds) {
        this.deleteIds = deleteIds;
    }

    public void setAdmin(String admin) {
        isAdmin = admin;
    }

    public void setResultSet(PageResultSet<SzRadio> resultSet) {
        this.resultSet = resultSet;
    }

    public SzRadio getRadio() {
        return radio;
    }

    public void setRadio(SzRadio radio) {
        this.radio = radio;
    }

    public RadioService getRadioService() {
        return radioService;
    }

    public void setRadioService(RadioService radioService) {
        this.radioService = radioService;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getServer() {
        return server;
    }

    public void setServer(String server) {
        this.server = server;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public Long getPageSize() {
        return pageSize;
    }

    public void setPageSize(Long pageSize) {
        this.pageSize = pageSize;
    }

    public Long getPage() {
        return page;
    }

    public void setPage(Long page) {
		this.page = page;
	}

	public String getIsAdmin() {
		return isAdmin;
	}

	public void setIsAdmin(String isAdmin) {
		this.isAdmin = isAdmin;
	}

    public String getActionName() {
        return actionName;
    }
}
